package com.yqg.protection.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.protection.common.Result;
import com.yqg.protection.common.interceptor.SysLog;
import com.yqg.protection.entity.FireBasicInfor;
import com.yqg.protection.mapper.FireBasicInforMapper;
import com.yqg.protection.service.IFireBasicInforService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * FireBasicInforController 前端控制器
 * @author zxf
 * @since 2024-10-16
 */
@RestController
@RequestMapping("/fire-basic-infor")
public class FireBasicInforController {

    @Resource
    private IFireBasicInforService fireBasicInforService;

    @Autowired
    private FireBasicInforMapper fireBasicInforMapper;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    @SysLog("新增或者修改消防安全基本情况")
    public Result save(@RequestBody FireBasicInfor fireBasicInfor) {
        fireBasicInfor.setIsDelete(0);
        return Result.success(fireBasicInforService.saveOrUpdate(fireBasicInfor));
    }
    /**
    *  删除
    */
    @DeleteMapping("delete/{id}")
    @SysLog("删除消防安全基本情况")
    public Result delete(@PathVariable Integer id) {
        FireBasicInfor fireBasicInfor =fireBasicInforService.getById(id);
        fireBasicInfor.setIsDelete(1);
        return Result.success(fireBasicInforService.saveOrUpdate(fireBasicInfor));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<FireBasicInfor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
       List<FireBasicInfor> list=  fireBasicInforService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(fireBasicInforService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           String keyWord,
                           Integer level,
                           Long organizationId,
                           String isAllClient,
                           @RequestParam List<Long> clientIds) {
        pageNum = pageSize * pageNum - pageSize;
        List<FireBasicInfor> fireBasicInfors = fireBasicInforMapper.findPage(pageNum, pageSize, organizationId, keyWord, level, isAllClient, clientIds);
        Long total = fireBasicInforMapper.findPageCount(organizationId, keyWord, level, isAllClient, clientIds);
        HashMap<String, Object> map = new HashMap<>();
        map.put("record", fireBasicInfors);
        map.put("total", total);
        return Result.success(map);
    }

    @ApiOperation("导出数据")
    @GetMapping("/export")
    public void export(HttpServletResponse response,
                       String keyWord,
                       Integer level,
                       Long organizationId,
                       String isAllClient,
                       @RequestParam List<Long> clientIds) {
        fireBasicInforService.export(response, organizationId, keyWord, level, isAllClient, clientIds);
    }

    @ApiOperation("导入数据")
    @PostMapping("/importData")
    @SysLog("导入消防安全基本情况")
    public void importData(MultipartFile file) {
        fireBasicInforService.importData(file);
    }

}

